<!DOCTYPE html>
<style>
	 body {
	   background:url("bg2.gif")  no-repeat center center;   /*加载背景图*/   /* 背景图不平铺 */
	   background-size:cover;  /* 让背景图基于容器大小伸缩 */
	   background-attachment:fixed;        /* 当内容高度大于图片高度时，背景图像的位置相对于viewport固定 */    //此条属性必须设置否则可能无效/
	   background-color:#CCCCCC;   /* 设置背景颜色，背景图加载过程中会显示背景色 */
	  font-family:YouYuan;
	 }
	 a{
		 color:white;
		  text-decoration:none;
	 }
	 a:hover{
		 color:pink;
		 transform:translatey(50px);
		 text-decoration:none;
	 }
	 input{
	 		 font-size:20px;
	 		 font-family:YouYuan;
	 		 background-color: whitesmoke;
	 }
</style>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		
	</head>
	<body>
	<a href="arrange.php" style="font-family: YouYuan;font-size:40px;color: #FFFFFF;">返回</a>
	<div style="text-align:center ;font-size:25px;margin-top:240px;">
		<h1>添加考试</h1>
		<form method="post" action="">
			<table align="center">
				<tr><th>考试班级：</th><td><input type="text" name="class" /></td></tr>
				<tr><th>考试科目：</th><td><input type="text" name="course" /></td></tr>
				<tr><th>考试时间：</th><td><input  type="text" name="time"/></td></tr>
				<tr><th>考试地点：</th><td><input type="text" name="room"/></td></tr>
				<tr><th>监考老师1：</th><td><input  type="text" name="teacher1"/></td></tr>
				<tr><th>监考老师2：</th><td><input  type="text" name="teacher2"/></td></tr>
				<tr>
					<td colspan="2" class="td-btn">
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="submit" value="保存资料" class="button"/>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="reset" value="重新填写" class="button" />
					</td>
				</tr>
			</table>
		</form>
	</div>
	</body>
</html>


<?php
	if(!empty($_POST)){
		$class = $_POST['class'];
		$course = $_POST['course'];
		$time = $_POST['time']; 
		$room = $_POST['room'];
		$tea1 = $_POST['teacher1'];
		$tea2 = $_POST['teacher2'];
		$tea = $tea1."、".$tea2;
		if($class!="" && $course!="" && $time!="" && $room!="" && $tea!=""){
			try{
			$db =new pdo("mysql:host=localhost;dbname=db_database10;charset=utf8","root","");
			}
			catch(Exception $exc){
				echo $exc->getMessage();
			}
			$stmt = $db->prepare('insert into exam(class,course,time,room,teacher) values(?,?,?,?,?)');
			$stmt->execute(array($class,$course,$time,$room,$tea));
			echo "<script>alert('添加成功！');location='arrange.php';</script>";
		}
		else
			echo "<script>alert('内容不能留空！请重新填写');location='add.php';</script>";
	}
?>
